public class test06 {
    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     int val;
     *     TreeNode left;
     *     TreeNode right;
     *     TreeNode() {}
     *     TreeNode(int val) { this.val = val; }
     *     TreeNode(int val, TreeNode left, TreeNode right) {
     *         this.val = val;
     *         this.left = left;
     *         this.right = right;
     *     }
     * }
     */
        public TreeNode sortedArrayToBST(int[] nums) {
            return traversal(nums,0,nums.length);
        }
        private TreeNode traversal(int[] nums,int begin,int end){
            if(begin>=end){
                return null;
            }
            int mid = begin+(end-begin)/2;
            TreeNode root = new TreeNode(nums[mid]);
            root.left = traversal(nums,begin,mid);
            root.right = traversal(nums,mid+1,end);
            return root;
        }
}
